import axios from 'axios'
import useLoginStore from '@/store/user/index.js'

const request = axios.create({
  baseURL: '/api',
  timeout: 5000000
})

request.interceptors.request.use((config) => {
  //设置请求token
  const loginStore = useLoginStore()
  if (loginStore.token) {
    config.headers.token = loginStore.token
  }
  return config
})

request.interceptors.response.use(
  (success) => {
    return success.data
  },
  (err) => {
    return Promise.reject(new Error(err.message))
  }
)

export default request
